<template>
  <view style="background: white">
    <uv-cell-group>
      <uv-cell label="设置账户的基础信息、头像、昵称等" title="基础信息" url="/pages/users/user_info/index" :isLink="true"
               arrow-direction="right"></uv-cell>
      <uv-cell label="完成学生认证可进行接单挣钱" url="/pages/users/user_auth/index" :isLink="true" arrow-direction="right">
        <template v-slot:title>
          <view style="display: flex">
            <text style="margin-right: 10px">学生认证</text>
            <view v-if="userInfo.studentInfo">
              <uv-tags size="mini" v-if="userInfo.studentInfo.state===1" text="已认证" plain type="success"></uv-tags>
              <uv-tags size="mini" v-if="userInfo.studentInfo.state===0" text="审核中" plain type="warning"></uv-tags>
              <uv-tags size="mini" v-if="userInfo.studentInfo.state===2" text="认证失败" plain type="error"></uv-tags>
            </view>
            <uv-tags size="mini" v-else text="待认证" plain type="error"></uv-tags>
          </view>
        </template>
      </uv-cell>
      <uv-cell label="如果您做了学生认证、可设置提现信息，方便后续佣金提现" url="/pages/users/user_set_settle_info/index" :isLink="true"
               arrow-direction="right">
        <template v-slot:title>
          <view style="display: flex">
            <text style="margin-right: 10px">设置提现信息</text>
            <view v-if="userCardInfo">
              <uv-tags size="mini" v-if="userCardInfo.state===1" text="已设置" plain type="success"></uv-tags>
              <uv-tags size="mini" v-if="userCardInfo.state===0" text="审核中" plain type="warning"></uv-tags>
              <uv-tags size="mini" v-if="userCardInfo.state===-1" text="审核失败" plain type="error"></uv-tags>
            </view>
            <uv-tags size="mini" v-else text="待设置" plain type="error"></uv-tags>
          </view>
        </template>
      </uv-cell>

      <uv-cell label="隐私政策条款" title="隐私政策" @click="toPrivacy('50000')" :isLink="true" arrow-direction="right"></uv-cell>
      <uv-cell label="用户协议" title="用户协议" @click="toPrivacy('50001')" :isLink="true" arrow-direction="right"></uv-cell>


      <uv-cell v-if="terminal==='H5' || terminal === 'APP'" label="设置或重置您账户的登录密码" title="登录密码" :isLink="true"
               arrow-direction="right"></uv-cell>


    </uv-cell-group>

    <!--        v-if="terminal==='H5' || terminal === 'APP'"-->
    <view class="logOutClass">
      <uv-button @click="outLogin" type="warning">退出登录</uv-button>
    </view>

  </view>
</template>

<script>
import {toLogin} from '@/libs/login.js';
import {mapGetters} from "vuex";
import * as UserCardInfoApi from '@/api/member/memberAccountCard.js';
import * as AuthApi from '@/api/member/auth.js';
import diyJson from '@/config/diy.js';
import * as Util from '@/utils/util.js';

const app = getApp();

export default {
  components: {
  },
  data() {
    return {
      diyData: diyJson.commonStyle,
      memberInfo: {},
      terminal: 'MP',
      pageBody: {
        background: 'white',
      },
      userCardInfo: undefined,

    };
  },
  computed: mapGetters(['isLogin', 'userInfo']),
  onLoad() {
    if (!this.isLogin) {
      toLogin();
    }
    console.log("Util.getTerminal()", Util.getTerminal())
  },
  onShow() {
    this.getCardInfo();
    let terminal = Util.getTerminal();
    this.terminal = terminal;
  },
  methods: {

    getCardInfo() {
      UserCardInfoApi.getByUserId().then(res => {
        this.userCardInfo = res.data;
      })
    },

    toPrivacy(code) {
      uni.navigateTo({
        url: `/pages/users/privacy/index?params=${encodeURIComponent(JSON.stringify({code: code}))}`
      })
    },

    /**
     * 退出登录
     */
    outLogin: function () {
      // if (this.terminal === 'H5'|| this.terminal === 'APP') {
      uni.showModal({
        title: '提示',
        content: '确认退出登录?',
        success: res => {
          if (!res.confirm) {
            console.log('用户点击取消');
            return
          }
          AuthApi.logout().then(res => {
            this.$store.commit("LOGOUT");
            uni.reLaunch({
              url: '/pages/index/index'
            });
          }).catch(err => {
            console.log(err);
          });
        }
      });
      // }
    },
  }
}
</script>
<style scoped lang="scss">

.logOutClass {
  margin: 100rpx 0;
  padding: 0 40rpx;
}
</style>
